<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>高血压筛选</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/dataTables.bootstrap.css" type="text/css">
    <link rel="stylesheet" href="../assets/css/views/modules/_common.scss">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <script src="${newframe}/js/compatible.js"></script>
    <script src="${js}/jquery-1.9.1.min.js"></script>
    <script src="../assets/js/views/vue.min.js"></script>
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <script src="${assets}/js/views/bpAbnormal.js"></script>
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <style>
        #news,
        #card{
            width: 80px;
            height: 17px;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            color: #666666;
        }
        #example_paginate{
            margin-top:15px;
            width:100%;
            text-align: center;
        }
        .form{
            margin-bottom:0px !important;
        }
        .content{
            height:auto !important;
        }
        .color{
            margin:0 !important;
        }
        span{
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            font-family: PingFang-SC-Regular;
        }
        .btn{
            float:right ;
            width:100px;
            font-size:16px;
            line-height:28px;
            background:#35acfd !important;
            margin-right:15px !important;
            padding:0 !important;
        }
        .infor div span{
            color:#666;

        }
        .infor .other span{
            width:40.7%;
            margin-right:5.36%;
        }
        #example_paginate{
            margin-top:15px;
            width:100%;
            text-align: center;
        }
        #mytool{
            width:96%;
        }
        .none{
            display:none
        }
        label{
            height: 16px;
            font-family: PingFang-SC-Regular;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #666666;
        }
        .tableWrap span{
            height: 16px;
            font-family: PingFang-SC-Regular;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #666666;
        }
        #accompanyType{
            width: 160px;
            height: 30px;
            border-radius: 5px;
            border: solid 1px #d0d0d0;
            line-height: 16px;
            font-family: PingFang-SC-Regular;
            font-size: 16px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #999999;
        }
        #beginDate,#endDate,input{
            width: 120px;
            height: 30px;
            border-radius: 5px;
            border: solid 1px #d0d0d0;
            font-family: PingFang-SC-Regular;
            font-size: 15px;
            font-weight: normal;
            font-stretch: normal;
            letter-spacing: 0px;
            color: #999999;
        }
        input{
            text-indent:10px;
            width:180px;
        }
        input[type=checkbox] {
            width:20px;
            height:20px;
            -webkit-appearance: none;
            border-radius:5px;
            border:1px solid #9e9e9e;
            vertical-align:top;
            margin-top:7px;
        }
        input[type=checkbox]:checked{
            background-image: url('../assets/images/radio.png');
            background-size:100% 100%;
            border:none
        }
        .content{
            height:auto !important;
        }
        #example_paginate{
            padding-bottom:30px;
        }
        .dataTables_empty{
            line-height:30px;
        }
        .clockParent{
            line-height:30px;
            vertical-align:middle;
            position:absolute;
            width:19%;
            text-align:center;
        }
        .clock{
            width:27px;
            height:30px;
            background: url("../assets/images/check.png") no-repeat;
            background-size: 100% 100%;
            display:inline-block;
            vertical-align:top;
            position:relative;
            left:70px;
            bottom:1px;
        }
    </style>
</head>
<body>
<div class="wrap">
    <%@ include file="../../breadline.jsp" %>
    <div class="content">
        <h1>随访提醒</h1>
        <div style="margin-left:18px;">
            <div style="" class="table">
                <label for="id_select" class="illtype" style="margin-right:20px;">信息搜索</label>
                <input type="text" placeholder="病人姓名" class="patientName">
                <label for="time" class="illtype" style="margin-left:29px;margin-right:20px;">时间</label>
                <div style="width:120px;display:inline-block;vertical-align:middle;margin-bottom:5px;">
                    <div id="PrevTime" class="input-group date form_date" style="width: 100%"  data-date-format="yyyy-mm-dd" >
                        <input id="beginDate" type="text" class="lay-date" placeholder="  开始日期" readonly>
                    </div>
                </div>
                -
                <div style="width:120px;display:inline-block;vertical-align:middle;margin-bottom:5px;">
                    <div id="PrevTime" class="input-group date form_date" style="width: 100%"  data-date-format="yyyy-mm-dd" style="width:120px;display:inline-block">
                        <input id="endDate" type="text" class="lay-date" placeholder="  截止日期" readonly>
                    </div>
                </div>
                <button onclick="search();" class="btn" style="float:none;color:white;margin-bottom:5px;margin-left:30px;">
                    <img src="../assets/images/search.png" alt="" style="width:16px;vertical-align: middle;"> 搜索
                </button>
            </div>
        </div>
        <div id="tablepart" style="margin-left:19px;margin-top:-32px;">
            <table id="example" class="display" cellspacing="10" width="100%">
                <thead>
                <tr style="background:#e6e6e6;">
                    <th>姓名</th>
                    <th>性别</th>
                    <th>身份证</th>
                    <th>下次随访时间</th>
                    <th>上次随访时间</th>
                    <th>级别管理</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
    <div class="loading" style="display: none;">
        <img src="${newframe }/images/slidebar/loading.gif" class="loadingImg">
    </div>
</div>
<script>
    var url = '${URL_ACCOMPANY_BPREMINDLIST}';
    var diseasesType = 1;
    function fun_date(aa){
        var date1 = new Date(),
            time1=date1.getFullYear()+"-"+(date1.getMonth()+1)+"-"+date1.getDate();//time1表示当前时间
        var date2 = new Date(date1);
        date2.setDate(date1.getDate()+aa);
        var time2 = date2.getFullYear()+"-"+(date2.getMonth()+1)+"-"+date2.getDate();
        return time2
    }
    var href = window.location.search;
    var isStorage = false;
    // 判断当前页面是否从面包线跳转过来
    if(  href.indexOf("isStorage") != -1){
        isStorage = true
    }
    var number = 0;
    function initTable() {
        table = $('#example').DataTable({
            "dom": "<'row'<'col-xs-2'l><'#mytool.col-xs-10'><'col-xs-6'f>r>" +
            "t" +
            "<'row'<''i><''p>>",
            "bFilter": false,//去掉搜索框
            "bAutoWidth": true, //自适应宽度
            "info": false,
            "bSort": false,
            "sPaginationType" : "full_numbers",
            "ordering": false,//是否允许Datatables开启排序
            "bProcessing" : true,
            "bServerSide" : true,
            "searching" : false, //去掉搜索框方法一
            'lengthChange' : false,
            "oPaginate":false,
            "sAjaxSource":url,
            "iDisplayStart" :number,
            "sAjaxDataProp": "dataList",//查询后，返回的集合
            "fnRowCallback" : function(nRow, aData, iDisplayIndex) {
                if ( aData.diseasesType === '请选择人群'){
                    aData.diseasesType = ""
                }else if( aData.diseasesType === '高血压人群'){
                    aData.diseasesType = "1"
                }else if( aData.diseasesType === '高血糖人群' ){
                    aData.diseasesType = "2"
                }
            },
            "fnServerData": function ( sSource, aoData, fnCallback ) {  //查询条件
                aoData.push(
                    {
                        "name": "patientName",
                        "value": $(".patientName").val()
                    },
                    {
                        "name": "startTime",
                        "value": $("#beginDate").val()
                    },
                    {
                        "name": "endTime",
                        "value": $("#endDate").val()
                    }
                ),
                    $.ajax( {
                        "dataType": 'json',
                        "url": sSource,
                        "type":'post',
                        "data": aoData,
                        "success": function(resp){

                            fnCallback(resp)
                        }
                    } );
            },
            "aoColumns" : [{
                "targets": 0,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html('' +
                        '&nbsp;&nbsp;<a href="#" onClick="Then(this)" style="color:black;border-bottom:#35acfd dashed 1px">'+oData.realname+'</a>' +
                        '');
                }
            }, {
                "targets": 1,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).text(oData.gander)
                }
            }, {
                "targets": 2,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    $(nTd).html("<a href='javascript:void(0)' data-id=" + oData.id_card + " onclick='Go(this)' class='searchBtn'>" + oData.id_card.slice(0,6) + '********' + oData.id_card.slice(14,18) + "</a>");
                }
            }, {
                "targets": 3,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    var curTime = new Date();
                    var nextTime = new Date(Date.parse(oData.next_accompany_time.slice(0,10)))
                    var startTime = new Date(Date.parse(curTime));
                    var endTime = new Date(Date.parse(fun_date(7)));
                    if( nextTime <= endTime ){
                        $(nTd).html('<p class="clockParent">'+ oData.next_accompany_time.slice(0,10)+'</p>'+ '<span class="clock"></span>');
                    }else{
                        $(nTd).text(oData.next_accompany_time.slice(0,10));
                    }
                }
            },{
                "targets": 4,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    if( oData.accompany_time){
                        $(nTd).text(oData.accompany_time.slice(0,10))
                    }else{
                        $(nTd).text("")
                    }
                }
            },{
                "targets": 5,
                "data": null,
                "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                    if( oData.level == '1' ){
                        $(nTd).text('一级管理')
                    }else if( oData.level == '2' ){
                        $(nTd).text('二级管理')
                    }else if( oData.level == '3' ){
                        $(nTd).text('三级管理')
                    }else{
                        $(nTd).text('')
                    }
                }
            }],
            "createdRow": function ( row, data, index ) {

            },
            "oLanguage": {//插件的汉化
                "sLengthMenu": "32",
                "sInfoEmpty" : "没有数据",
                "sInfoFiltered" : "(从 _MAX_ 条数据中检索)",
                "oPaginate" : {
                    "sFirst" : "",
                    "sPrevious" : "<b>上一页<b>",
                    "sLast" : "",
                    "sNext" : "<i>下一页</i>"

                },
                "sZeroRecords" : "没有检索到数据",
                "sProcessing" : "<img src='' />",
                "sSearch" : "搜索"
            }

        });
    }
    $(document).ready(function() {
        if( isStorage ){
            number = (Number(sessionStorage.getItem('pageNumber'))-1)*10;
        }
        $('#beginDate').val('2019-01-01');
        initTable();
        $('#beginDate').val('');
        initLayDate('#beginDate');
        initLayDate('#endDate')
    })
    function search(){
        if( $('#beginDate').val() == ''  ){
            $('#beginDate').val('2019-01-01');
            refreshTable();
            $('#beginDate').val('');
        }else{
            refreshTable();
        }
    }
    function Go(obj){
        var rowIndex = $(obj).parents("tr").index();
        var id = $('#example').DataTable().row(rowIndex).data().id;//此处拿到隐藏列的id
        // var name = obj.innerText;
        var name = $(obj).attr('data-id');
        // 判断
        $.ajax({
            url:"${URL_SCREENING_GETBREADLINE}",
            dataType:'json',
            type:'post',
            success:function(data){
                breadLine = JSON.parse(data.data)
                var url = '${URL_ACCOMPANY_BPACCOMPANYS}?idcard=' + name + '&id=' + id +'&diseasesType='+diseasesType
                breadLine.push({
                    name:'随访信息',
                    href:url
                })
                $.ajax({
                    url:'${URL_SCREENING_SAVEBREADLINE}',
                    data:{
                        breadLine:JSON.stringify(breadLine)
                    },
                    dataType:'json',
                    type:'post',
                    success:function(data){
                        parent.showSrc('${URL_ACCOMPANY_BPACCOMPANYS}?idcard=' + name + '&id=' + id +'&diseasesType='+diseasesType)
                    }
                })
            }
        })
    }
    function Then(obj){
        // var idcard = obj.parentNode.parentNode.children[2].children[0].innerText;
        var idDom = obj.parentNode.parentNode.children[2].children[0];
        var idcard = $(idDom).attr('data-id');
        var rowIndex = $(obj).parents("tr").index();
        var id = $('#example').DataTable().row(rowIndex).data().id;//此处拿到隐藏列的id
        $.ajax({
            url:"${URL_SCREENING_GETBREADLINE}",
            dataType:'json',
            type:'post',
            success:function(data){
                breadLine = JSON.parse(data.data)
                var url = '${URL_ACCOMPANY_BPACCOMPANYS}?idcard=' + idcard + '&id=' + id +'&diseasesType='+diseasesType
                breadLine.push({
                    name:'随访信息',
                    href:url
                })
                $.ajax({
                    url:'${URL_SCREENING_SAVEBREADLINE}',
                    data:{
                        breadLine:JSON.stringify(breadLine)
                    },
                    dataType:'json',
                    type:'post',
                    success:function(data){
                        parent.showSrc('${URL_ACCOMPANY_BPACCOMPANYS}?idcard=' + idcard + '&id=' + id +'&diseasesType='+diseasesType)
                    }
                })
            }
        })
    }
    function getValue(){
        var oTable = $('#example').dataTable();
        var oSettings = oTable.fnSettings();
        // 获取页码值
        return oSettings._iDisplayStart;
    }
    window.onbeforeunload=function(e){
        var e = window.event||e;
        var pageNumber = getValue()
        // 获取当前页码
        if( pageNumber == 0 ){
            pageNumber = 1;
        }else{
            pageNumber = pageNumber/10 + 1;
        }
        console.log(pageNumber)
        // 保存在本地
        sessionStorage.setItem('pageNumber',pageNumber);
    }
</script>
</body>
</html>
